using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;  // 添加 TextMeshPro 命名空间

public class MainMenuUI : MonoBehaviour
{
    [Header("UI组件")]
    public Button startButton;              // 开始游戏按钮
    public Button exitButton;               // 退出按钮
    public TextMeshProUGUI messageText;     // 提示信息文本

    [Header("场景设置")]
    public string gameSceneName = "SampleScene";      // 游戏主场景名称
    public string loginSceneName = "LoginScene";    // 登录场景名称

    private void Start()
    {
        // 初始化按钮监听
        startButton.onClick.AddListener(OnStartButtonClick);
        exitButton.onClick.AddListener(OnExitButtonClick);
    }

    private void OnStartButtonClick()
    {
        // 显示加载提示
        ShowMessage("正在进入游戏...");
        // 加载游戏主场景
        SceneManager.LoadScene(gameSceneName);
    }

    private void OnExitButtonClick()
    {
        // 显示确认对话框
        ShowMessage("确定要返回登录界面吗？");
        // 返回登录场景
        SceneManager.LoadScene(loginSceneName);
    }

    private void ShowMessage(string message)
    {
        if (messageText != null)
        {
            messageText.text = message;
            // 3秒后清除消息
            StartCoroutine(ClearMessage());
        }
    }

    private System.Collections.IEnumerator ClearMessage()
    {
        yield return new WaitForSeconds(3f);
        messageText.text = "";
    }

    private void OnDestroy()
    {
        // 移除按钮监听
        startButton.onClick.RemoveListener(OnStartButtonClick);
        exitButton.onClick.RemoveListener(OnExitButtonClick);
    }
} 